package fr.inserm.um915.jimpute.model;

public enum Chromosome
	{
	chr1,
	chr2,
	chr3,
	chr4,
	chr5,
	chr6,
	chr7,
	chr8,
	chr9,
	chr10,
	chr11,
	chr12,
	chr13,
	chr14,
	chr15,
	chr16,
	chr17,
	chr18,
	chr19,
	chr20,
	chr21,
	chr22,
	chrX,//chrX_nonPAR
	chrY,
	chrM,
	chrX_PAR1,
	chrX_PAR2,
	chr1_gl000191_random,
	chr1_gl000192_random,
	chr1_random,
	chr2_random,
	chr3_random,
	chr4_ctg9_hap1,
	chr4_gl000193_random,
	chr4_gl000194_random,
	chr4_random,
	chr5_h2_hap1,
	chr5_random,
	chr6_apd_hap1,
	chr6_cox_hap1,
	chr6_cox_hap2,
	chr6_dbb_hap3,
	chr6_hla_hap1,
	chr6_hla_hap2,
	chr6_mann_hap4,
	chr6_mcf_hap5,
	chr6_qbl_hap2,
	chr6_qbl_hap6,
	chr6_random,
	chr6_ssto_hap7,
	chr7_gl000195_random,
	chr7_random,
	chr8_gl000196_random,
	chr8_gl000197_random,
	chr8_random,
	chr9_gl000198_random,
	chr9_gl000199_random,
	chr9_gl000200_random,
	chr9_gl000201_random,
	chr9_random,
	chr10_random,
	chr11_gl000202_random,
	chr11_random,
	chr12_random,
	chr13_random,
	chr15_random,
	chr16_random,
	chr17_ctg5_hap1,
	chr17_gl000203_random,
	chr17_gl000204_random,
	chr17_gl000205_random,
	chr17_gl000206_random,
	chr17_random,
	chr18_gl000207_random,
	chr18_random,
	chr19_gl000208_random,
	chr19_gl000209_random,
	chr19_random,
	chr21_gl000210_random,
	chr21_random,
	chr22_h2_hap1,
	chr22_random,
	chrUn_gl000211,
	chrUn_gl000212,
	chrUn_gl000213,
	chrUn_gl000214,
	chrUn_gl000215,
	chrUn_gl000216,
	chrUn_gl000217,
	chrUn_gl000218,
	chrUn_gl000219,
	chrUn_gl000220,
	chrUn_gl000221,
	chrUn_gl000222,
	chrUn_gl000223,
	chrUn_gl000224,
	chrUn_gl000225,
	chrUn_gl000226,
	chrUn_gl000227,
	chrUn_gl000228,
	chrUn_gl000229,
	chrUn_gl000230,
	chrUn_gl000231,
	chrUn_gl000232,
	chrUn_gl000233,
	chrUn_gl000234,
	chrUn_gl000235,
	chrUn_gl000236,
	chrUn_gl000237,
	chrUn_gl000238,
	chrUn_gl000239,
	chrUn_gl000240,
	chrUn_gl000241,
	chrUn_gl000242,
	chrUn_gl000243,
	chrUn_gl000244,
	chrUn_gl000245,
	chrUn_gl000246,
	chrUn_gl000247,
	chrUn_gl000248,
	chrUn_gl000249,
	chrX_random
	
	;
	
	public static Chromosome parsePLinkOpcode(int opcode)
		{
		if(opcode>0 || opcode<23)
			{
			return values()[opcode-1];
			}
		switch(opcode)
			{
			case 23: return chrX;
			case 24: return chrY;
			case 26: return chrM;
			}
		throw new IllegalArgumentException("bad opcode"+opcode);
		}
	
	public Integer toPlinkOpcode()
		{
		switch(this)
			{
			case chr1: case chr2:  case chr3:  case chr4: case chr5:
			case chr6: case chr7:  case chr8:  case chr9: case chr10:
			case chr11: case chr12:  case chr13:  case chr14: case chr15:
			case chr16: case chr17:  case chr18:  case chr19: case chr20:
			case chr21: case chr22:   return ordinal()+1;
			case chrX: return 23;
			case chrY: return 24;
			case chrM: return 26;
			default:return null;
			}
		}
	
	public static Chromosome parse(String s)
		{
		if(s==null || s.isEmpty()) return null;
		while(s.startsWith("0")) s=s.substring(1);
		if(!s.toLowerCase().startsWith("chr")) s="chr"+s;
		
		for(Chromosome c:Chromosome.values())
			{
			if(s.equalsIgnoreCase(c.name())) return c;
			}
		if(s.equalsIgnoreCase("chr23")) return chrX;
		if(s.equalsIgnoreCase("chr24")) return chrY;
		if(s.equalsIgnoreCase("chr26")) return chrM;
		return null;
		}
	
	}
